package com.bigmodel.bistu;


import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class Main {

    public static final int TOTAL_COUNT = 50;

    public static void main(String[] args) throws Exception {
        // 历年分数
        lnfsBuild();
        // 招生计划
        zsjhBuild();
    }

    public static void lnfsBuild() throws Exception {
        LNFSDataBuilder lnfsDataBuilder = new LNFSDataBuilder();
        lnfsDataBuilder.getTokenByHttp();
        JSONObject param = lnfsDataBuilder.getParam();
        int count = 0;
        for (String key : param.keySet()) {
            if (count == TOTAL_COUNT) {
                break;
            }
            JSONArray arr = param.getJSONArray(key);
            for (int i = 0; i < arr.size(); i++) {
                JSONObject obj = arr.getJSONObject(i);
                Map<String, String> map = new HashMap<>();
                map.put("ssmc", key);
                map.put("zsnf", obj.getStr("nf"));
                map.put("klmc", obj.getStr("klmc"));
                map.put("zslx", obj.getStr("zslx"));
                lnfsDataBuilder.getTokenByHttp();
                lnfsDataBuilder.getData(map);
            }
            lnfsDataBuilder.saveDocFile(key);
            count++;
        }
    }

    public static void zsjhBuild() throws Exception {
        ZSJHDataBuilder zsjhDataBuilder = new ZSJHDataBuilder();
        zsjhDataBuilder.getTokenByHttp();
        JSONObject param = zsjhDataBuilder.getParam();
        int count = 0;
        for (String key : param.keySet()) {
            if (count == TOTAL_COUNT) {
                break;
            }
            JSONArray arr = param.getJSONArray(key);
            for (int i = 0; i < arr.size(); i++) {
                JSONObject obj = arr.getJSONObject(i);
                Map<String, String> map = new HashMap<>();
                map.put("ssmc", key);
                map.put("zsnf", obj.getStr("nf"));
                map.put("klmc", obj.getStr("klmc"));
                map.put("zslx", obj.getStr("zslx"));
                zsjhDataBuilder.getTokenByHttp();
                zsjhDataBuilder.getData(map);
            }
            zsjhDataBuilder.saveDocFile(key);
            count++;
        }
    }
}
